package com.example.mychat.Controller;

import com.example.mychat.Pojo.Result;
import com.example.mychat.Pojo.UserInfo;
import com.example.mychat.Service.UserService;
import com.example.mychat.Service.wsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
//@CrossOrigin(origins = "http://localhost:7000")
@CrossOrigin(origins = "*")
@Slf4j
public class UserCtrl {
    @Autowired
    private UserService userService;
    @Autowired
    private wsService wsservice;

    @PostMapping("/login")
    public Result Login(@RequestBody UserInfo list) {
        return userService.login(list);
    }

    @PostMapping("/signup/getCaptcha")
    public Result signUp_Captcha(@RequestBody String email) {
       String nemail= email.substring(1, 18);
        log.info("邮件请求"+nemail);
        return userService.sendEmail(nemail);
    }

    @PostMapping("/signup/submit")
    public Result signUp_submit(@RequestBody UserInfo info) {
        log.info(info.toString());
        return userService.signUp(info);
    }


    /**
     * 获取用户的聊天数据
     *
     * @param userid 用户id
     * @return
     */
    @GetMapping("/getUserData")
    public Result getuserdata(String userid) {
        log.info("查询用户chat" + userid);
        return Result.success(wsservice.getfriendchatdata(userid));
    }

    @PostMapping("Setting/ResetPasswd")
    public Result changeUserPasswd(@RequestBody UserInfo userInfo) {
        log.info(userInfo.toString());
        return userService.resetUserPasswd(userInfo);
    }
}
